<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>科室列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script src="./js/jquery.min.js"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">

                            <form class="layui-form layui-col-space5" lay-filter="example">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="tdepartmentsName" id="tdepartmentsName" placeholder="请输二级科室名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="button" class="layui-btn layui-icon"  lay-submit="" lay-filter="sreach"  value=&#xe615;></input>
                                </div>
                            </form>
                        </div>

                        <div class="layui-card-body ">
                            <table class="layui-table layui-form layui-hide" id="test" lay-filter="test">

                            </table>
                        </div>

                    </div>
                </div>
            </div>
        </div> 
    </body>

    <script type="text/html" id="action">
            <a title="禁用" onclick="member_del(this,'{{d.tdepartmentsId}}')" href="javascript:;">
                <i class="layui-icon">&#xe601;</i>
            </a>
    </script>

    <script>
        var token =  localStorage.getItem("token");
        var  head = new Headers();
        head.append('token',token);
        layui.use(['form','table'], function(){
            var table = layui.table;
            var form = layui.form;

            form.on('submit(sreach)', function(data){
                var name = $("#name").val();
                var tdepartmentsName = $("#tdepartmentsName").val();

                table.render({
                    elem: '#test'
                    ,url: '/hospital/api/back/departments/limit1?forbidden=1' //数据接口
                    ,page: true //开启分页
                    ,limit:20,
                    headers: {
                        'token':token
                    }
                    ,where: {"tdepartmentsName":tdepartmentsName}
                    ,done:function () {//渲染完成后的回调

                    },parseData:function(res){
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total, //解析数据长度
                            "data": res.data.list //解析数据列表
                        };

                    },response:{
                        statusCode:0
                    }
                    ,cols: [[ //表头
                        //,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                        ,{field: 'tdepartmentsId', title: 'ID', width:'10%'}
                        ,{field:'tdepartmentsName',title:'二级科室名称',width:'30%'}
                        ,{field: 'departmentsName', title: '一级科室名称', width:'20%'}
                        ,{fixed:'right',title:'操作',toolbar:'#action',width:'10%',class:"td-manage"}
                    ]]
                });
            });
        });


      /*科室-禁用*/
      function member_del(obj,id){
          layer.confirm('确认要启用吗？',function(index){
              //发异步删除数据
              $.ajax({
                  type:"get",
                  url:"/hospital/api/back/departments/forbidden",
                  data:{"tdepartments": id,"forbidden":1
                  },
                  headers: {
                      'token':token
                  },
                  dataType:"json",
                  success:function(msg){
                      if(msg.code==0){
                          $(obj).parents("tr").remove();
                          layer.msg('已启用!',{icon:1,time:1000});
                      }
                      else{
                          layer.msg("启用失败！");
                      }

                  }
              });

          });
      }


    </script>

    <script>

        layui.use(['layer', 'form','table'], function(){
            var table = layui.table;
            var form = layui.form;



            table.render({
                elem: '#test'
                ,url: '/hospital/api/back/departments/limit1?forbidden=1' //数据接口
                ,page: true //开启分页
                ,limit:20,
                headers: {
                    'token':token
                }
                ,done:function () {//渲染完成后的回调

                },parseData:function(res){
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };

                },response:{
                    statusCode:0
                }
                ,cols: [[ //表头
                    //,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                    ,{field: 'tdepartmentsId', title: 'ID', width:'10%'}
                    ,{field:'tdepartmentsName',title:'二级科室名称',width:'30%'}
                    ,{field: 'departmentsName', title: '一级科室名称', width:'20%'}
                    ,{fixed:'right',title:'操作',toolbar:'#action',width:'10%',class:"td-manage"}
                ]]
            });


        });





    </script>


</html>